package longrise.phone.com.bjjt_henan.main;

import android.content.Context;
import android.text.method.ScrollingMovementMethod;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.TextView;

import com.longrise.android.FormParameter;
import com.longrise.android.LFView;

import java.io.BufferedReader;
import java.io.InputStream;
import java.io.InputStreamReader;

import longrise.phone.com.bjjt_henan.R;

/**
 * Created by Administrator on 2017/5/17.
 */

public class InspectRuleView extends LFView {

    private Context mContext;

    private View mView;

    public InspectRuleView(Context context) {
        super(context);
        this.mContext = context;
    }

    @Override
    public FormParameter getFormParameter() {
        FormParameter form = new FormParameter();
        form.setShowtitle(false);
        return form;
    }

    @Override
    public View getView() {
        return mView;
    }

    @Override
    public void init() {
        if (null == mContext) {
            return;
        }
        mView = LayoutInflater.from(mContext).inflate(R.layout.view_inspectrule, null);
        //标题栏
        TextView titleTV = (TextView) mView.findViewById(R.id.tv_title);
        titleTV.setText(R.string.car_rule);
        mView.findViewById(R.id.hn_btn_back).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                closeForm();
                OnDestroy();
            }
        });
        TextView infoTV = (TextView) mView.findViewById(R.id.inspectrule_tv);
        infoTV.setMovementMethod(new ScrollingMovementMethod());
        infoTV.setText(getStringFromAsset("inspectrule.txt"));
    }

    private String getStringFromAsset(String filename) {
        BufferedReader br = null;
        try {
            StringBuilder sb = new StringBuilder();
            InputStream is = mContext.getAssets().open(filename);
            String line;
            br = new BufferedReader(new InputStreamReader(is));
            while ((line = br.readLine()) != null) {
                sb.append(line).append("\r\n");
            }
            return sb.toString();
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            if (br != null) {
                try {
                    br.close();
                } catch (Exception e) {
                }
            }
        }
        return null;
    }

    @Override
    public void refresh() {

    }

    @Override
    public void refreshByTime() {

    }

    @Override
    public void OnDestroy() {
        super.OnDestroy();
        mView = null;
    }
}
